'/
' ProjectName
' 
' =========================================================================
' 
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
' 
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
' 
' You should have received a copy of the GNU General Public License
' along with this program.  If not, see <http://www.gnu.org/licenses/>.
'/

type ResourceManager extends Base

	'// -------------------------------------------------------------------------------------------------------------
	'// Default sprite animation speed (ms).
	'// -------------------------------------------------------------------------------------------------------------
	global DEFAULT_ANIM_SPEED:short = 200;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Initialize the resource manager.
	'// -------------------------------------------------------------------------------------------------------------
	method init()
	
		sConsoleManager.writeLog("Initializing resource manager.");
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Load all sounds to memory.
	'// -------------------------------------------------------------------------------------------------------------
	method loadSounds()
	
		sConsoleManager.writeLog("Loading sounds.");
		'sSoundManager.loadSound("clickButton", "Data/Sounds/Interface/click_button.wav");
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Load all images to memory.
	'// -------------------------------------------------------------------------------------------------------------
	method loadImages()
	
		sConsoleManager.writeLog("Loading images.");
		loadImg("cursor", "Data/Images/Interface/Cursor1.png");
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Load an image from a file into memory.
	'// -------------------------------------------------------------------------------------------------------------
	method loadImg(id:string, url:string)
	
		if (not fileType(url)) ..
			sGUI.error("Error 030: Could not find image '" + url + "'.");
		
		sConsoleManager.writeLog("... " + url);
		m_imageMap.insert(id, loadImage(url));
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Return a poniter to an image contained in the image hashtable.
	'// -------------------------------------------------------------------------------------------------------------
	method getImg:TImage(id:string)
	
		return TImage(m_imageMap.valueForKey(id));
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Container for all the images loaded into memory.
	'// -------------------------------------------------------------------------------------------------------------
	field m_imageMap:TMap = new TMap;

end type

global sResourceManager:ResourceManager = new ResourceManager;
